import { permission } from "process";
import { BaseEntity } from "src/modules/common/entities/BaseEntity";
import { Menu } from "src/modules/menu/entities/menu.entity";
import { Permission } from "src/modules/menu/entities/menu.permission.entity";
import { User } from "src/modules/user/entities/user.entity";
import { Column, Entity, JoinTable, ManyToMany, ManyToOne } from "typeorm";

@Entity()
export class Role extends BaseEntity {
  @Column()
  name: string;

  @Column({
    nullable: true
  })
  description: string;

  @ManyToMany(() => User)
  user: User[];

  @ManyToMany(() => Menu)
  @JoinTable({
    name: "role_menu",
    joinColumn: { name: "role_id", referencedColumnName: "id" },
    inverseJoinColumn: { name: "menu_id", referencedColumnName: "id" }
  })
  menu: Menu[];

  @ManyToMany(type => Permission, permission => permission.role)
  permission: Permission[];
}